import time

from selenium.webdriver.common.by import By
from common.common import driver

# 个人中心测试
class TestCenter:
    url=""
    driver=""

    def __init__(self):
        self.driver=driver.driver
        self.url="http://127.0.0.1:58080/index.html#"
        self.driver.get(self.url)

    # 个人信息
    def personal_information(self):
        # 点击主页头像
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        # 点击个人中心
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_settings").click()
        # 找到用户中心标题即跳转成功
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div > h2").text
        assert text=="用户中心"
        # 添加屏幕截图
        driver.getScreeShot()
        # 检查用户名是否正确
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR,"#settings_nickname").text
        assert text=="wyr123"

        # 修改昵称
        # 清空输入框，输入内容，点击修改
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#setting_input_nickname").send_keys("wyr1234")
        self.driver.find_element(By.CSS_SELECTOR,"#setting_submit_nickname").click()
        # 出现成功弹窗即修改成功
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text=="成功"
        # 添加屏幕截图
        driver.getScreeShot()
        # 不修改内容，点击修改
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_nickname").click()
        # 出现警告即修改失败
        time.sleep(0.5)
        text=self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text=="警告"
        # 添加屏幕截图
        driver.getScreeShot()

        time.sleep(3)
        # 修改邮箱地址
        # 清空输入框，输入内容，点击修改
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        # 出现成功弹窗即修改成功
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text == "成功"
        # 添加屏幕截图
        driver.getScreeShot()
        # 不修改内容，点击修改
        time.sleep(3)
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        # 出现警告即修改失败
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text == "警告"
        # 添加屏幕截图
        driver.getScreeShot()

        time.sleep(3)
        # 修改电话号码
        # 清空输入框，输入内容，点击修改
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_phoneNum").click()
        # 出现成功弹窗即修改成功
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text == "成功"
        # 添加屏幕截图
        driver.getScreeShot()


        time.sleep(3)
        # 修改个人简介
        # 滚动到页面最底部
        driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(3)
        # 清空输入框，输入内容，点击修改
        self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_remark").click()
        # 出现成功弹窗即修改成功
        time.sleep(0.5)
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2").text
        assert text == "成功"
        # 添加屏幕截图
        driver.getScreeShot()


        # 修改密码
        # 输入原密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123")
        # 输入新密码和确认密码
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123")
        # 点击提交修改
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()
        # 修改成功跳转登录界面，若找到登录按钮则修改成功
        time.sleep(0.5)
        self.driver.find_element(By.CSS_SELECTOR, "#submit")
        # 添加屏幕截图
        driver.getScreeShot()

